/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
void show(auto &container)
{
    for(auto element:container)
    {
        cout << element << " ";
    }
    cout << endl;
}
void adjacent_find_all(auto & container)
{
    auto iter=adjacent_find(container.begin(),container.end());
    if (iter!=container.end())
    {
        do
        {
            cout << "The adjacent repeating element "<<*iter<<" is at " <<distance(container.begin(),iter)<< endl;
            ++iter;
        }
        while ((iter=adjacent_find(iter,container.end()))!=container.end());
    }
    else
    {
        cout << "There is no adjacent repeating element in the container." << endl;
    }
}
void adjacent_find_all_if(auto & container,auto & binary_predicate)
{
    auto iter=adjacent_find(container.begin(),container.end(),binary_predicate);
    if (iter!=container.end())
    {
        do
        {
            cout << "The adjacent repeating element "<<*iter<<" is at " <<distance(container.begin(),iter)<< endl;
            ++iter;
        }
        while ((iter=adjacent_find(iter,container.end(),binary_predicate))!=container.end());
    }
    else
    {
        cout << "There is no adjacent repeating element in the container." << endl;
    }
}
bool is_prime(int num)
{
    if (num<=1)
    {
        return false;
    }
    else
    {
        int upper_factor=floor(sqrt(num));
        for (int i=2;i<=upper_factor ;++i )
        {
            if (0==num%i)
            {
                return false;
            }
        }
        return true;
    }
}
bool duplicate_prime(int cur,int next)
{
    return is_prime(cur)&&is_prime(next);
}
int main_31()
{
    srand((unsigned int)time(nullptr));
    vector<int> int_vect;
    int random_int;
    for (int i=0; i<20 ; ++i )
    {
        random_int=rand()%20;
        int_vect.push_back(random_int);
    }
    show(int_vect);
    adjacent_find_all(int_vect);
    cout << "binary_predicate" << endl;
    adjacent_find_all_if(int_vect,duplicate_prime);
    return 0;
}
